//导航栏固定
$(function(){
var nav=$(".navfix"); //得到导航对象
var win=$(window); //得到窗口对象
var sc=$(document);//得到document文档对象。
win.scroll(function(){
  if(sc.scrollTop()>=100){
    nav.addClass("fixednav"); 
   $(".navTmp").fadeIn(); 
  }else{
   nav.removeClass("fixednav");
   $(".navTmp").fadeOut();
  }
})  
})

//导航栏二级菜单
$(function(){
	$(".ull>li").mouseover(function(){
		var index=$(this).index();
		console.log($(this).index());
		$(".nav_hidden>div").hide();
		$(".nav_hidden>div").eq(index).show();
	})
	$(".nav_hidden").mouseleave(function(){
		$(".nav_hidden>div").hide();
	})
	
})
//脚步图片触碰更换
$(".changea").hover(function(){
  $(this).attr("src","images/xinlangb_03.png")
})
$(".changea").mouseleave(function(){
  $(this).attr("src","images/xinlang_03.png")
})

$(".changeb").hover(function(){
  $(this).attr("src","images/weixinb_05.png")
})
$(".changeb").mouseleave(function(){
  $(this).attr("src","images/weixin_05.png")
})

$(".changec").hover(function(){
  $(this).attr("src","images/tengxunb_07.png")
})
$(".changec").mouseleave(function(){
  $(this).attr("src","images/tengxun_07.png")
})
//颜色选择
$(function(){
	$(".color_choose>.color_choosea").click(function(){
		var index=$(this).index(".color_choosea");
		console.log(index);
		$(this).css("border","2px solid #29a9df").siblings().css("border","1px solid #dddddd");
		$(".buy_img").hide()
		$(".buy_img").eq(index).show()
	})
})

//内存选择
$(function(){
	$(".tf_choose>.tf_choosea").click(function(){
		var index=$(this).index(".tf_choosea");
		console.log(index);
		$(this).css("border","2px solid #29a9df").siblings().css("border","1px solid #dddddd");
		
	})
})

//套装切换
$(function(){
	$(".taozhuang>div>span").click(function(){
		var index=$(this).index();
		console.log(index);
		$(this).css({"color":"#1428a0","font-weight":"bold","border-bottom":"3px solid #1428a0"}).siblings().css({"color":"#000","font-weight":"normal","border-bottom":"none"});
		$(".taozhuang>ul>li").fadeOut(300)
		$(".taozhuang>ul>li").eq(index).fadeIn(500)
		console.log(".taozhuang>ul>li")
	})
})

//规格
$(function(){
	$(".details>div>a").click(function(){
		var index=$(this).index();
		console.log(index);
		$(this).css({"color":"#1428a0","font-weight":"bold","border-bottom":"3px solid #1428a0"}).siblings().css({"color":"#000","font-weight":"normal","border-bottom":"none"});

	})
})


//放大镜
$(".demo").mouseover(function(){
	$(".float-box").css("display","block")
	$(".big-box").css("display","block")
})
$(".demo").mouseleave(function(){
	$(".float-box").css("display","none")
	$(".big-box").css("display","none")
})

var $main_box=$(".demo")
var $small_box=$(".float-box")
var $big_box=$(".big-box")
var $big_img=$(".bigimg")


    $main_box.mousemove(function(event){
      event = event || window.event;
		 var pagex = event.pageX || scroll().top + event.clientX;
		 var pagey = event.pageY || scroll().left + event.clientY;
		 var boxLeft = pagex - $main_box.offset().left - $small_box.width()/2; 
		 var boxTop = pagey - $main_box.offset().top - $small_box.height()/2;
         if(boxLeft < 0){
		 	boxLeft = 0;
		 }
		  if(boxTop < 0){
		 	boxTop = 0;
		 }  
		 if(boxLeft > $main_box.width()-$small_box.width()){
		 	boxLeft = $main_box.width()-$small_box.width();
		 }
		 if(boxTop > $main_box.height()-$small_box.height()){
		 	boxTop = $main_box.height()-$small_box.height();
		 }
		 $small_box.css({    
		 	left: boxLeft,
		 	top: boxTop
		 });
		 
		 var biLiLeft =  ($big_img.width()-$big_box.width())/($main_box.width()-$small_box.width());
		 var biLiTop = ($big_img.height()-$big_box.height())/($main_box.height()-$small_box.height());
		 var imgLeft = biLiLeft * boxLeft;
		 var imgTop = biLiLeft * boxTop;

		 $big_img.css({
		 	left: -imgLeft,
		 	top: -imgTop
		 });
    })
//小图选择
$(".bottom_img").click(function(){
	var index=$(this).index(".bottom_img");
	console.log(index)
	$(this).css("border-color","#1428a0").siblings().css("border-color","transparent");
	$(".demo").css("display","none")
	$(".demo").eq(index).css("display","block")
})
